import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.event.*;
import java.util.*;
import com.toedter.calendar.*;
import java.sql.*;

public class searchGui extends JPanel implements ActionListener
{
	private String myDriver = "com.mysql.jdbc.Driver";
	private	String ipOfDB = "localhost";
	private	MySQLdriverConnection msc;
	private	Connection Conn;
	private Vector mediaTypeV=null, catNameV=null;
	private JComboBox mediaTypeJcb=null, catNameJcb=null, searchJcb=null;
	private JScrollPane mediaTypeJsp=null, catNameJsp=null;
	private JButton searchStockB=null, editB=null, delB=null;
	
	public searchGui() 
	{
		JPanel northP = new JPanel( );
		
		BoxLayout b1 = new BoxLayout(northP, BoxLayout.X_AXIS);
		northP.setLayout(b1);
		JLabel searchLbl = new JLabel(" Stock Item Search ");
		JTextField searchTxt = new JTextField();
		Vector searchV = new Vector();
		searchV.addElement(" Name ");
		searchV.addElement(" Stock ID ");
		searchV.addElement(" Serial No. ");
		JComboBox searchJcb = new JComboBox(searchV);
		JScrollPane scrollP = new JScrollPane(searchJcb ,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		JButton searchB = new JButton(" Search ");
		searchB.addActionListener(this);
		northP.add(searchLbl);
		northP.add(searchTxt);
		northP.add(searchJcb);
		northP.add(searchB);
		northP.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		JPanel baseP = new JPanel(new BorderLayout());
		
		JPanel westP = new JPanel(new BorderLayout());
		
		JPanel northP2 = new JPanel();
		JLabel stockAttrib = new JLabel(" Media Stock Attributes ");
		northP2.add(stockAttrib);
		
		JPanel centerP = new JPanel(new GridLayout(1,1));
				
		westP.add(centerP, BorderLayout.EAST);
		westP.add(northP2, BorderLayout.NORTH);
		
		JPanel eastP = new JPanel();
		BoxLayout b3 = new BoxLayout(eastP, BoxLayout.Y_AXIS);
		eastP.setLayout(b3);
		JTextArea jta = new JTextArea(null, 15, 28);
		JScrollPane jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
							JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
							
		eastP.add(jsp);					
		JPanel eastP3 = new JPanel();
		
		JTextField medStockIdTxt = new JTextField(25);
		medStockIdTxt.setEditable(false);
		JTextField barcodeTxt = new JTextField(25);
		JTextField brandTxt = new JTextField(25);
		brandTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField serialNoTxt = new JTextField(25);
		JTextField descriptionTxt = new JTextField(25);
		//JTextField catIdTxt = new JTextField(25);
		JTextField titleTxt = new JTextField(25);
		titleTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);		
		JTextField runTimeTxt = new JTextField(25);
		runTimeTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);		
		JTextField ageRestTxt = new JTextField(25);
		ageRestTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);				
		JTextField directorTxt = new JTextField(25);
		directorTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField actor1Txt = new JTextField(25);
		actor1Txt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField actor2Txt = new JTextField(25);
		actor2Txt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		
		JDateChooser lastRentedJdc = new JDateChooser();
		JDateChooser releaseDateJdc = new JDateChooser();
				
		JLabel mediaStockId = new JLabel(" Stock ID ");
		JLabel mediaTypeName = new JLabel(" Media Type Name ");
		JLabel brand = new JLabel(" Brand ");
		JLabel barcode = new JLabel(" Barcode ");
		JLabel serialNo = new JLabel(" Serial No. ");
		JLabel description = new JLabel(" Description ");
		JLabel catId = new JLabel(" Category ID ");
		JLabel title = new JLabel(" Title ");
		JLabel status = new JLabel(" Status ");
		JLabel releaseDate = new JLabel(" Release Date");
		JLabel genre = new JLabel(" Genre ");
		JLabel runTime = new JLabel(" Run Time ");
		JLabel ageRest = new JLabel(" Age Restriction ");
		JLabel director = new JLabel(" Director ");
		JLabel actor1 = new JLabel(" Actor 1 ");
		JLabel actor2 = new JLabel(" Actor 2 ");
		JLabel dateLastRented = new JLabel(" Date Last Rented ");
		
		Vector genreV = new Vector();
		genreV.addElement(" Action ");
		genreV.addElement(" Adventure ");
		genreV.addElement(" Animation ");
		genreV.addElement(" Biography ");
		genreV.addElement(" Comedy ");
		genreV.addElement(" Crime ");
		genreV.addElement(" Documentary ");
		genreV.addElement(" Drama ");
		genreV.addElement(" Family ");
		genreV.addElement(" Fantasy ");
		genreV.addElement(" Film-Noir ");
		genreV.addElement(" Game-Show ");
		genreV.addElement(" History ");
		genreV.addElement(" Horror ");
		genreV.addElement(" Music ");
		genreV.addElement(" Musical ");
		genreV.addElement(" Mystery ");
		genreV.addElement(" News ");
		genreV.addElement(" Reality-TV ");
		genreV.addElement(" Romance ");
		genreV.addElement(" Sci-Fi ");
		genreV.addElement(" Short ");
		genreV.addElement(" Sport ");
		genreV.addElement(" Talk-Show ");
		genreV.addElement(" Thriller ");
		genreV.addElement(" War ");
		genreV.addElement(" Western ");
		
		JComboBox genreJcb = new JComboBox(genreV);
		JScrollPane genreJsp = new JScrollPane(genreJcb ,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		
		try
		{
			msc = new MySQLdriverConnection("","",ipOfDB,"turtledata");
			Conn = msc.getConnection();
		}
		catch(SQLException sqlE)
		{
			sqlE.printStackTrace();
		}	
		catch(ClassNotFoundException cnfe)
		{
			cnfe.printStackTrace();
		}
	
		mediaTypeV = new Vector();
		
		try
		{
			Statement popMediaVectStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet mediaVectRS;
			String stockTypeTableQuery = "SELECT stockTypeName FROM stockTypeTable";
			mediaVectRS = popMediaVectStmt.executeQuery(stockTypeTableQuery);
			String tempSTR;
			mediaVectRS.last();
			int rows = mediaVectRS.getRow();
			mediaVectRS.first();
			mediaTypeV = new Vector();
			for(int i = 1;i <= rows;i++ )
			{
				tempSTR = mediaVectRS.getString(1);
				
				System.out.println(""+tempSTR);
				mediaTypeV.addElement(tempSTR);
				
				mediaVectRS.next();
			}
		}
		catch(SQLException sqlE)
		{
			System.out.println("No problemo");
			sqlE.printStackTrace();
		}//end catch
		
		mediaTypeJcb = new JComboBox(mediaTypeV); 
		mediaTypeJsp = new JScrollPane(mediaTypeJcb , JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		
		try
		{
			msc = new MySQLdriverConnection("","",ipOfDB,"turtledata");
			Conn = msc.getConnection();
		}
		catch(SQLException sqlE)
		{
			sqlE.printStackTrace();
		}	
		catch(ClassNotFoundException cnfe)
		{
			cnfe.printStackTrace();
		}
	
		catNameV = new Vector();
		
		try
		{
			Statement popCatNameVectStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet catNameRS;
			String priceCatTableQuery = "SELECT catName FROM pricecattable";
			catNameRS = popCatNameVectStmt.executeQuery(priceCatTableQuery);
			String tempSTR;
			catNameRS.last();
			int rows = catNameRS.getRow();
			catNameRS.first();
			catNameV = new Vector();
			for(int i = 1;i <= rows;i++ )
			{
				tempSTR = catNameRS.getString(1);
				
				System.out.println(""+tempSTR);
				catNameV.addElement(tempSTR);
				
				catNameRS.next();
			}
		}
		catch(SQLException sqlE)
		{
			System.out.println("No problemo");
			sqlE.printStackTrace();
		}//end catch
		
		catNameJcb = new JComboBox(catNameV); 
		catNameJsp = new JScrollPane(catNameJcb , JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		
		Vector statusV = new Vector();
		statusV.addElement(" In ");	
		statusV.addElement(" Out ");
		statusV.addElement(" Damaged ");
		statusV.addElement(" Unavailable ");
		
		JComboBox statusJcb = new JComboBox(statusV);
		JScrollPane statusJsp = new JScrollPane(statusJcb ,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
				
		GroupLayout layout  = new GroupLayout(eastP3);
		layout.setAutoCreateContainerGaps(true);
		layout.setAutoCreateGaps(true);
		eastP3.setLayout(layout);
		GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
		
		vGroup.addGroup(layout.createParallelGroup().
        addComponent(mediaStockId).addComponent(mediaTypeName).
        addComponent(title).addComponent(status).
        addComponent(barcode).addComponent(brand).
        addComponent(serialNo).addComponent(description).
        addComponent(catId).addComponent(runTime).
        addComponent(releaseDate).addComponent(genre).
        addComponent(ageRest).addComponent(serialNo).
        addComponent(director).addComponent(actor1).
        addComponent(actor2).addComponent(dateLastRented));
  	    vGroup.addGroup(layout.createParallelGroup().
        addComponent(medStockIdTxt).addComponent(mediaTypeJcb).
        addComponent(titleTxt).addComponent(statusJcb).
        addComponent(barcodeTxt).addComponent(brandTxt).
        addComponent(serialNoTxt).addComponent(descriptionTxt).
        addComponent(catNameJcb).addComponent(runTimeTxt).
        addComponent(releaseDateJdc).addComponent(genreJcb).
        addComponent(ageRestTxt).addComponent(serialNoTxt).
        addComponent(directorTxt).addComponent(actor1Txt).
        addComponent(actor2Txt).addComponent(lastRentedJdc));
   		layout.setHorizontalGroup(vGroup);
   		   		   		
   		GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
		hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(mediaStockId).addComponent(medStockIdTxt));
   		hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(mediaTypeName).addComponent(mediaTypeJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(title).addComponent(titleTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(status).addComponent(statusJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(barcode).addComponent(barcodeTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(brand).addComponent(brandTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(serialNo).addComponent(serialNoTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(description).addComponent(descriptionTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(catId).addComponent(catNameJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(runTime).addComponent(runTimeTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(releaseDate).addComponent(releaseDateJdc));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(genre).addComponent(genreJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(ageRest).addComponent(ageRestTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(director).addComponent(directorTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(actor1).addComponent(actor1Txt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(actor2).addComponent(actor2Txt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(dateLastRented).addComponent(lastRentedJdc));
        layout.setVerticalGroup(hGroup);
        
        centerP.add(eastP3);
		
		JPanel southP = new JPanel(); 
		BoxLayout b4 = new BoxLayout(southP, BoxLayout.X_AXIS);
		southP.setLayout(b4);
		JButton editB = new JButton(" Edit ");
		editB.setToolTipText(" Edit stock item ");
		editB.addActionListener(this);
		JButton delB = new JButton(" Delete ");
		delB.setToolTipText(" Delete stock item ");	
		delB.addActionListener(this);
		JButton returnB = new JButton(" Return "); 
		returnB.setToolTipText(" Return to main page ");
		
		southP.add(editB);
		southP.add(delB);
		southP.add(returnB);	
		southP.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		baseP.add(northP2, BorderLayout.NORTH);
		baseP.add(westP, BorderLayout.WEST);
		baseP.add(eastP, BorderLayout.EAST);
		baseP.add(southP, BorderLayout.SOUTH);
		
		//setup "this" Jpanel
		this.setLayout(new GridLayout(1,1));
		this.add(baseP);	
	}
	
	public void actionPerformed(ActionEvent e)
	{
		Object source = e.getSource();
		if(source == searchStockB)
		{
			if(((String)searchJcb.getSelectedItem()).equals("Name"))
			{
				
			}
			else if(((String)searchJcb.getSelectedItem()).equals(" Stock ID "))
			{
				
			}
			else if(((String)searchJcb.getSelectedItem()).equals(" Serial No. "))
			{
				
			}
		}
		
		if(source == editB)
		{
			
		}
		
		if(source == delB)
		{
			
		}
	}	
}
